<div class="subscriptions index">
    <h2>
        <?php echo $title; ?>
        <?php echo $this->Html->link(__('+ New Subscribe'), array('action' => 'add', 'admin' => true), array('class' => 'btn  btn-primary btn-fl-r')) ?>
    </h2>

    <table cellpadding="0" cellspacing="0">
        <tr>
            <th><?php echo $this->Paginator->sort('user_id', __('Member')); ?></th>
            <th><?php echo $this->Paginator->sort('subscription_term_id', __('Plan')); ?></th>
            <th><?php echo $this->Paginator->sort('expire_date'); ?></th>
            <th><?php echo $this->Paginator->sort('Status'); ?></th>
            <th><?php echo __('Remains') ?></th>
            <th class="actions">&nbsp;</th>
        </tr>
        <?php 
            foreach ($subscriptions as $subscription):
                $days = $this->News->coundDate($subscription['Subscription']['expire_date']);
                $alert = '';
                if ( $days < 15 ) {
                    $alert = 'class="expired-warming"';
                }
            ?>
            <tr <?php echo $alert ?> >
                <td>
                    <?php echo $subscription['User']['name']; ?>
                </td>
                <td>
                    <?php echo $subscription['SubscriptionTerm']['name']; ?>
                </td>
                <td><?php echo h($subscription['Subscription']['expire_date']); ?>&nbsp;</td>
                <td>
                    <?php 
                        
                        switch(intval($subscription['Subscription']['active'])) {
                            case SUBSCRIPTION_STATUS_PADDING:
                                echo __('Padding');
                                $status = $this->Form->postLink(__('Active'), array('action' => 'changeStatus', $subscription['Subscription']['id'], false, 'admin' => true), null, __('Are you sure you want to active # %s?', $subscription['Subscription']['id']));
                                break;
                            case SUBSCRIPTION_STATUS_DEACTIVE:
                                echo __('Deactive');
                                $status = $this->Form->postLink(__('Active'), array('action' => 'changeStatus', $subscription['Subscription']['id'], false, 'admin' => true), null, __('Are you sure you want to active # %s?', $subscription['Subscription']['id']));
                                break;
                            case SUBSCRIPTION_STATUS_ACTIVE:
                                echo __('Active');
                                $status = $this->Form->postLink(__('Deactive'), array('action' => 'changeStatus', $subscription['Subscription']['id'], true, 'admin' => true), null, __('Are you sure you want to deactive # %s?', $subscription['Subscription']['id']));
                                break;
                            case SUBSCRIPTION_STATUS_EXPIRED:
                                echo __('Expired');
                                $status = '';
                                break;
                        }
                    ?>
                &nbsp;</td>
                <td><?php echo __('%s days', $days); ?></td>
                <td class="actions">

                    <?php //echo $this->Html->link(__('Edit'), array('action' => 'edit', $subscription['Subscription']['id'])); ?>
                    <?php echo $status;  ?>
                    <?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $subscription['Subscription']['id'], 'admin' => true), null, __('Are you sure you want to delete # %s?', $subscription['Subscription']['id'])); ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
    <p>
        <?php
        echo $this->Paginator->counter(array(
            'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
        ));
        ?>	</p>

    <div class="paging">
        <?php
        echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('separator' => ''));
        echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
        ?>
    </div>
</div>